package DesignPattern;

/**
 * 构造者模式
 */
class ComputerBuilder {
    private final String cpu;//必须
    private final String ram;//必须
    private final String computerName;//

    private ComputerBuilder(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.computerName = builder.computerName;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", computerName='" + computerName + '\'' +
                '}';
    }

    public static class Builder {
        private String cpu;//必须
        private String ram;//必须
        private String computerName;//可选

        public Builder(String computerName) {
            this.computerName = computerName;
        }

        public Builder setCpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder setRam(String ram) {
            this.ram = ram;
            return this;
        }

        public ComputerBuilder build() {
            return new ComputerBuilder(this);
        }
    }
    public static void main(String[] args) {
        ComputerBuilder computer = new ComputerBuilder.Builder("mycomputer")
                .setCpu("inter")
                .setRam("512G")
                .build();
        System.out.println(computer.toString());
    }
}
